﻿namespace BEGDC.CC.Web.UserControls
{
	using System;
	using System.Data;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;
	using BEGDC.CC.Web.UserControls;
	using BEGDC.CC.BL.CCFlow.CR;
	using BEGDC.CC.Entity;
	using BEGDC.CC.BL.Workflow;
	using BEGDC.CC.BL.Common;
	using BEGDC.Utility.Castle;
	using BEGDC.CC.BL.Common.Query;

	/// <summary>
	///		Summary description for ActionLog.
	/// </summary>
	public class ActionLog : System.Web.UI.UserControl
	{
		protected System.Web.UI.WebControls.DataGrid DG_ActionLog;
		protected System.Web.UI.WebControls.Label lbAppNo;

		private int ApplicationID
		{
			get
			{
				string appID = this.Request.QueryString["AppID"];
				if (appID == null ) return 0;
				return Convert.ToInt32(appID);
			}
		}

		protected new virtual BEGDC.CC.Entity.Application Application
		{
			get
			{
					if( Session[this.ApplicationID.ToString()] != null ) 
					return (BEGDC.CC.Entity.Application)Session[this.ApplicationID.ToString()];
				return null;
			}
			set{ Session[this.ApplicationID.ToString()] = value; }
		}

		private void Page_Load(object sender, System.EventArgs e)
		{

				InitForm();
		}

		#region InitForm
		private void InitForm()
		{
			//INIT QUESTION TABLE
			if(this.ApplicationID>=0)
			{
				IQuery QueryService = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
				DataTable ActionLogTable = QueryService.GetApplicationActionLog(this.ApplicationID);
				this.DG_ActionLog.DataSource = ActionLogTable;
				this.DG_ActionLog.DataBind();
				if(this.Application != null)
					this.lbAppNo.Text = this.Application.AppNo;

			}
		}

        void DG_ActionLog_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            //throw new NotImplementedException();
            if (e.Item.Cells[3].Text.ToString() == "Query")
                e.Item.Cells[3].Text = "Ask for more";
            else if(e.Item.Cells[3].Text.ToString() == "ReplyQuery")
                e.Item.Cells[3].Text = "Reply Ask for more";
            if (e.Item.Cells[2].Text == "SSMEHeadApproval")
                e.Item.Cells[2].Text = "IBGHeadApproval";
            if (e.Item.Cells[3].Text == "Callback")
                e.Item.Cells[3].Text = "Drawback";      
        }

		#endregion

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);
            this.DG_ActionLog.ItemDataBound += new DataGridItemEventHandler(DG_ActionLog_ItemDataBound);

		}

		#endregion
	}
}
